<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>设置/获取 字符编码的检测顺序</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.mb-detect-encoding.html">« mb_detect_encoding</a></li>
      <li style="float: right;"><a href="function.mb-encode-mimeheader.html">mb_encode_mimeheader »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.mbstring.html">多字节字符串 函数</a></li>
    <li>设置/获取 字符编码的检测顺序</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.mb-detect-order" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mb_detect_order</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.6, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">mb_detect_order</span> &mdash; <span class="dc-title">设置/获取 字符编码的检测顺序</span></p>

 </div>
   
 <div class="refsect1 description" id="refsect1-function.mb-detect-order-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mb_detect_order</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$encoding_list</code><span class="initializer"> = mb_detect_order()</span></span>): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>

  <p class="para rdfs-comment">
   为编码列表 <code class="parameter">encoding_list</code> 设置自动检测字符编码的顺序。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mb-detect-order-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">encoding_list</code></dt>

     <dd>

      <p class="para">
       <code class="parameter">encoding_list</code> 是一个 <span class="type">array</span> 或者逗号分隔的字符编码列表。
       参见<a href="mbstring.supported-encodings.html" class="link">支持的编码</a>。
      </p>
      <p class="para">
       如果省略了 <code class="parameter">encoding_list</code> 参数，它将返回当前字符编码检测顺序的数组。
      </p>
      <p class="para">
       该设置会影响 <span class="function"><a href="function.mb-detect-encoding.html" class="function">mb_detect_encoding()</a></span> 和 <span class="function"><a href="function.mb-send-mail.html" class="function">mb_send_mail()</a></span>。
      </p>
      <p class="para">
       <code class="literal">mbstring</code> 当前实现了以下编码检测筛选器。
       如有以下编码列表的无效字节序列，编码的检测将会失败。
      </p>
      <span class="simpara">
       <code class="literal">UTF-8</code>, <code class="literal">UTF-7</code>,
       <code class="literal">ASCII</code>,
       <code class="literal">EUC-JP</code>,<code class="literal">SJIS</code>,
       <code class="literal">eucJP-win</code>, <code class="literal">SJIS-win</code>,
       <code class="literal">JIS</code>, <code class="literal">ISO-2022-JP</code> 
      </span>
      <p class="para">
       对于 <code class="literal">ISO-8859-*</code>，<code class="literal">mbstring</code>
       总是检测为 <code class="literal">ISO-8859-*</code>。
      </p>
      <p class="para">
       对于 <code class="literal">UTF-16</code>、<code class="literal">UTF-32</code>、
       <code class="literal">UCS2</code> 和 <code class="literal">UCS4</code>，编码检测总是会失败。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.mb-detect-order-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   设置编码检测顺序时候，成功时返回 <strong><code>true</code></strong>，识别时候返回  <strong><code>false</code></strong>。
  </p>
  <p class="para">
   在获取编码检测顺序的时候，会返回排序过的编码数组。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mb-detect-order-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2566">
    <p><strong>示例 #1 <span class="function"><strong>mb_detect_order()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;为检测顺序设置枚举列表&nbsp;*/<br /></span><span style="color: #0000BB">mb_detect_order</span><span style="color: #007700">(</span><span style="color: #DD0000">"eucjp-win,sjis-win,UTF-8"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;通过数组设置检测顺序&nbsp;*/<br /></span><span style="color: #0000BB">$ary</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #DD0000">"ASCII"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$ary</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #DD0000">"JIS"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$ary</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #DD0000">"EUC-JP"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">mb_detect_order</span><span style="color: #007700">(</span><span style="color: #0000BB">$ary</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;显示当前的检测顺序&nbsp;*/<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">implode</span><span style="color: #007700">(</span><span style="color: #DD0000">",&nbsp;"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mb_detect_order</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
      <p class="para">
       <div class="example" id="example-2567">
        <p><strong>示例 #2 案例展示了无效的检测顺序</strong></p>
        <div class="example-contents">
<div class="cdata"><pre>
; 总是检测为 ISO-8859-1
detect_order = ISO-8859-1, UTF-8

; 总是检测为 UTF-8，由于 ASCII/UTF-7 的值对  UTF-8 是有效的
detect_order = UTF-8, ASCII, UTF-7
</pre></div>
        </div>

       </div>
      </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mb-detect-order-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.mb-internal-encoding.html" class="function" rel="rdfs-seeAlso">mb_internal_encoding()</a> - 设置/获取内部字符编码</span></li>
    <li class="member"><span class="function"><a href="function.mb-http-input.html" class="function" rel="rdfs-seeAlso">mb_http_input()</a> - 检测 HTTP 输入字符编码</span></li>
    <li class="member"><span class="function"><a href="function.mb-http-output.html" class="function" rel="rdfs-seeAlso">mb_http_output()</a> - 设置/获取 HTTP 输出字符编码</span></li>
    <li class="member"><span class="function"><a href="function.mb-send-mail.html" class="function" rel="rdfs-seeAlso">mb_send_mail()</a> - 发送编码过的邮件</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>